﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace limpalex.bbparser
{
    public class TagList
    {
        private readonly Hashtable _list = new Hashtable();

        public void AddTag(Tag options)
        {
            _list.Add(options.Name, options);
        }

        public void AddTags(IEnumerable<Tag> optionList)
        {
            foreach (Tag option in optionList)
            {
                AddTag(option); 
            }
        }

        public bool Exists(string name)
        {
            return _list.ContainsKey(name.ToLower(Tag.TagNameCulture));
        }

        public Tag this[string name]
        {
            get
            {
                return _list[name.ToLower(Tag.TagNameCulture)] as Tag;
            }
            set
            {
                _list[name.ToLower(Tag.TagNameCulture)] = value;
            }
        }

        public static TagList Create(XmlNode node)
        {
            var result = new TagList();

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                    continue;
                result.AddTag(Tag.Create(child));
            }

            return result;
        }
    }
}
